package second.dp;

public class Solution30 {
    public int rob(int[] nums) {
        if (nums.length == 1) return nums[0];
        return Math.max(robACct(nums, 0, nums.length - 2), robACct(nums, 1, nums.length - 1));
    }

    public int robACct(int[] nums, int i, int j) {
        int dp0 = 0;
        int dp1 = nums[i];
        int res = dp1;
        for (int k = i + 1; k <= j; k++) {
            res = Math.max(dp0 + nums[k], dp1);
            dp0 = dp1;
            dp1 = res;
        }
        return res;
    }
}
